﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Pages_BuyTicket : System.Web.UI.Page
{
	protected void Page_Load(object sender, EventArgs e)
	{
		if (!IsPostBack)
		{
			InitControls();
		}
	}

	protected void InitControls()
	{
		IList<Station> stations = DBEntity<Station>.Select();
		ddlStartStantion.DataSource = stations;
		ddlStartStantion.DataBind();

		if(stations.Count() > 0)
			stations.RemoveAt(0);

		ddlEndStantion.DataSource = stations;
		ddlEndStantion.DataBind();

		tbDate.Text = DateTime.Now.ToShortDateString();
	}

	protected void ddlStartStantion_SelectedIndexChanged(object sender, EventArgs e)
	{


		//IList<Station> stations = DBEntity<Station>.Select();

		//if (stations.Count() > 0)
		//{
		//    Station remove = stations.SingleOrDefault(s => s.Id == DS.ToInt64(ddlStartStantion.SelectedValue));
		//    if (remove != null)
		//        stations.Remove(remove);
		//}

		//ddlEndStantion.DataSource = stations;
		//ddlEndStantion.DataBind();
		
	}

	protected void btnSearch_Click(object sender, EventArgs e)
	{
		Ticket t = new Ticket();
		t.SourceStation_id = DS.ToInt64(ddlStartStantion.SelectedValue);
		t.TargetStation_id = DS.ToInt64(ddlEndStantion.SelectedValue);
		t.Ticket_DateTime = DS.ToDateTime(tbDate.Text.Trim());
		gvBuses.DataSource = DBEntity<Ticket>.ExecAsDataset(t, "FindTrip");
		gvBuses.DataBind();
	}
}